package com.smart.web.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.smart.dao.Page;
import com.smart.dao.PageRequest;
import com.smart.model.Info;
import com.smart.model.InfoCond;
import com.smart.model.SelectItem;

@Controller
public class IndexController extends BaseController {
	@RequestMapping(value = "index.html")
	public String index(Model model, PageRequest pageRequest) {
		pageRequest.setLimit(5);
		InfoCond cond = new InfoCond();
		SelectItem item = selectItemService.findByCode("info.wealth");
		cond.setTypeId(item.getId());
		cond.addOrderByDesc("timeCreated");
		Page<Info> infoPage = infoService.findAll(pageRequest, cond);
		List<Info> infos = infoPage.getContent();
		model.addAttribute("infos", infos);
		
		handleSelectedMenu();
		return "index";
	}
	
	@RequestMapping(value = "/")
	public String index1(Model model, PageRequest pageRequest) {
		return index(model, pageRequest);
	}

	@RequestMapping(value = "/2")
	public String index2(Model model, PageRequest pageRequest) {
		handleSelectedMenu();
		return "index2";
	}
}
